package nc.impl.gl.glvoucher;

import java.util.Map;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.gl.querymiddle.IQueryMiddleService;
import nc.jdbc.framework.processor.BeanProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapProcessor;
import nc.vo.glcom.ass.AssVO;
import nc.vo.org.AccbookVO;
import nc.vo.org.DeptVO;
import nc.vo.pub.BusinessException;

public class IQueryMiddleImpl implements IQueryMiddleService {

	private BaseDAO baseDAO = null;

	public BaseDAO getBaseDAO() {
		if (baseDAO == null) {
			baseDAO = new BaseDAO();
		}
		return baseDAO;
	}

	public AccbookVO byCodeGetAccBookVO(String code) throws DAOException {
		String sql = "select * from org_accbook where code ='" + code + "'";
		AccbookVO accbookVO = (AccbookVO) getBaseDAO().executeQuery(sql, new BeanProcessor(AccbookVO.class));
		return accbookVO;
	}

	public void translateDept(AssVO assVO, String bookPK) throws BusinessException {

		AccbookVO bookVO = byPKGetAccBookVO(bookPK);
		String sql = "select * from org_dept where code = '" + assVO.getCheckvaluecode() + "' and pk_org = '"
				+ bookVO.getPk_relorg() + "'";
		DeptVO deptVO = (DeptVO) getBaseDAO().executeQuery(sql, new BeanProcessor(DeptVO.class));
		if (deptVO != null) {
			assVO.setCheckvaluecode(deptVO.getCode());
			assVO.setChecktypename(deptVO.getName());
			assVO.setPk_Checkvalue(deptVO.getPk_dept());
		} else {
			assVO.setCheckvaluecode(null);
			assVO.setChecktypename(null);
			assVO.setPk_Checkvalue(null);
			assVO.setCheckvaluename(null);
		}
	}

	private AccbookVO byPKGetAccBookVO(String pk) throws DAOException {
		String sql = "select * from org_accbook where pk_accbook ='" + pk + "'";
		AccbookVO accbookVO = (AccbookVO) getBaseDAO().executeQuery(sql, new BeanProcessor(AccbookVO.class));
		return accbookVO;
	}
}
